<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义指令</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>

<body>
    <div id="app">
        <input type="text" v-focus>自定义指令</input>
        <input type="text" v-focu>
    </div>


    <script>
        // 全局注册 bg inserted的函数
        Vue.directive('focus',{
            inserted:function(el){
                // el是当前的dom节点
                console.log(el);
                // window对象
                console.log(this);
                el.focus();
            }
        })
      
        var app = new Vue({
            el: "#app",
           directives:{
               focu:{
                   inserted:function(el){
                    //    同上
                       console.log(this);
                       console.log(el);
                       el.focus();
                   }
               }
           }
        })

    </script>
</body>

</html>